This eliminates the usage of the legacy queue code for route lists.
class route_head
{
public:
- queue Q; /* Link onto parent list. */
queue waypoint_list; /* List of child waypoints */
QString rte_name;
QString rte_desc;
typedef void (*route_trl)(const route_head*);
// TODO: Consider using composition instead of private inheritance.
-class RouteList : private QueueList<queue>
+class RouteList : private QList<route_head*>
{
public:
-// FIXME: The interface should NOT depend on the implementation of the list.
-// Migrate to std::sort using a compare function
-// typedef bool (*Compare)(const route_head* a, const route_head* b);
- typedef int (*Compare)(const queue* a, const queue* b);
+ typedef bool (*Compare)(const route_head* a, const route_head* b);
- RouteList();
-
- int count() const; // a.k.a. size()
int waypt_count() const;
void add_head(route_head* rte); // a.k.a. append(), push_back()
// FIXME: Generally it is inefficient to use an element pointer or reference to define the element to be deleted, use iterator instead,
// Our contained element (route_head) also contains a container (waypoint_list),
// and we maintain a total count the elements in these contained containers, i.e.
// the total number of waypoints in all the routes in the RouteList.
- using QueueList<queue>::begin;
- using QueueList<queue>::end;
- using QueueList<queue>::cbegin;
- using QueueList<queue>::cend;
- using QueueList<queue>::empty; // a.k.a. isEmpty()
- using QueueList<queue>::front; // a.k.a. first()
- using QueueList<queue>::back; // a.k.a. last()
- using QueueList<queue>::Iterator;
- using QueueList<queue>::ConstIterator;
+ using QList<route_head*>::begin;
+ using QList<route_head*>::end;
+ using QList<route_head*>::cbegin;
+ using QList<route_head*>::cend;
+ using QList<route_head*>::empty; // a.k.a. isEmpty()
+ using QList<route_head*>::front; // a.k.a. first()
+ using QList<route_head*>::back; // a.k.a. last()
+ using QList<route_head*>::count; // a.k.a. size()
+ using QList<route_head*>::iterator;
+ using QList<route_head*>::const_iterator;
+ typedef iterator Iterator;
+ typedef const_iterator ConstIterator;
private:
- queue head;
- int head_ct{0};
int waypt_ct{0};
};
void
RouteList::disp_all(T1 rh, T2 rt, T3 wc)
{
- queue* elem, *tmp;
- QUEUE_FOR_EACH(&head, elem, tmp) {
- const route_head* rhp;
- rhp = reinterpret_cast<route_head*>(elem);
+ foreach (const route_head* rhp, *this) {
// rh != nullptr, caught with an overload of common_disp_all
rh(rhp);
route_disp(rhp, wc);
void
RouteList::disp_all(std::nullptr_t /* rh */, T2 rt, T3 wc)
{
- queue* elem, *tmp;
- QUEUE_FOR_EACH(&head, elem, tmp) {
- const route_head* rhp;
- rhp = reinterpret_cast<route_head*>(elem);
+ foreach (const route_head* rhp, *this) {
// rh == nullptr
route_disp(rhp, wc);
// rt != nullptr, caught with an overload of common_disp_all
void
RouteList::disp_all(T1 rh, std::nullptr_t /* rt */, T3 wc)
{
- queue* elem, *tmp;
- QUEUE_FOR_EACH(&head, elem, tmp) {
- const route_head* rhp;
- rhp = reinterpret_cast<route_head*>(elem);
+ foreach (const route_head* rhp, *this) {
// rh != nullptr, caught with an overload of common_disp_all
rh(rhp);
route_disp(rhp, wc);
void
RouteList::disp_all(std::nullptr_t /* rh */, std::nullptr_t /* rt */, T3 wc)
{
- queue* elem, *tmp;
- QUEUE_FOR_EACH(&head, elem, tmp) {
- const route_head* rhp;
- rhp = reinterpret_cast<route_head*>(elem);
+ foreach (const route_head* rhp, *this) {
// rh == nullptr
route_disp(rhp, wc);
// rt == nullptr
*/
/*
- * Documentation can be found at http://www.trackmaker.com/download/ref_guide_eng.pdf
+ * Documentation can be found at
+ * https://www.trackmaker.com/download/ref_guide_eng.pdf
+ * https://www.trackmaker.com/download/GTM211_format.pdf
*/
#include "defs.h"
#include "jeeps/gpsmath.h"
+#include <QtCore/QList>
static gbfile* file_in, *file_out;
static int indatum;
static void
gtm_read()
{
- route_head* first_trk_head = nullptr;
route_head* trk_head = nullptr;
route_head* rte_head = nullptr;
Waypoint* wpt;
- int real_tr_count = 0;
+ QList<route_head*> real_track_list;
unsigned int icon;
int i;
if (start_new || !trk_head) {
trk_head = route_head_alloc();
track_add_head(trk_head);
- real_tr_count++;
- if (!first_trk_head) {
- first_trk_head = trk_head;
- }
+ real_track_list.append(trk_head);
}
track_add_wpt(trk_head, wpt);
}
/* Tracklog styles */
- trk_head = first_trk_head;
- for (i = 0; i != ts_count && i != real_tr_count; i++) {
- trk_head->rte_name = fread_string(file_in);
+ // TODO: The format document states there are ts_count tracklog style entries,
+ // and tr_count tracklog entries.
+ // Some tracklog entries may be contiuation entries, so we turn these into
+ // real_track_list.size() <= tr_count tracks.
+ // If ts_count != real_track_list.size() we don't know how to line up the tracklogs,
+ // and the real tracks, with the tracklog styles.
+ if (ts_count != real_track_list.size()) {
+ warning(MYNAME ": The number of tracklog entries with the new flag set doesn't match the number of tracklog style entries.");
+ }
+ for (i = 0; i != ts_count; i++) {
+ QString tname = fread_string(file_in);
fread_discard(file_in, 12);
- trk_head = reinterpret_cast<route_head *>QUEUE_NEXT(&trk_head->Q);
+ if (i < real_track_list.size()) {
+ trk_head = real_track_list.at(i);
+ trk_head->rte_name = tname;
+ }
}
/* Routes */
#include "defs.h"
#include "grtcirc.h" // for RAD, gcdist, heading_true_degrees, radtometers
-#include "queue.h" // for queue, dequeue, QUEUE_FOR_EACH, QUEUE_MOVE, QUEUE_INIT, sortqueue, ENQUEUE_TAIL, QUEUE_EMPTY, ENQUEUE_AFTER, ENQUEUE_HEAD, QUEUE_LAST, QUEUE_NEXT, QueueList
+#include "queue.h" // for dequeue, queue, QUEUE_FOR_EACH, QUEUE_EMPTY, ENQUEUE_HEAD, ENQUEUE_TAIL, QUEUE_INIT, QUEUE_LAST, QUEUE_NEXT
#include "session.h" // for curr_session, session_t (ptr only)
#include "src/core/datetime.h" // for DateTime
#include "src/core/optional.h" // for optional, operator>, operator<
#include <QtCore/QDateTime> // for QDateTime
+#include <QtCore/QList> // for QList<>::iterator
#include <QtCore/QString> // for QString
+#include <QtCore/QtGlobal> // for foreach
+#include <algorithm> // for sort
#include <cstddef> // for nullptr_t
RouteList* global_route_list;
global_track_list->insert_head(rte, predecessor);
}
-// FIXME: can we delete this unused and untested code?
-#ifdef DEAD_CODE_IS_REBORN
-static
-route_head*
-common_route_by_name(queue* routes, const char* name)
-{
- queue* elem, *tmp;
-
- QUEUE_FOR_EACH(routes, elem, tmp) {
- route_head* rte = reinterpret_cast<route_head*>(elem);
- if (rte->rte_name == name) {
- return rte;
- }
- }
-
- return nullptr;
-}
-
-route_head*
-route_find_route_by_name(const char* name)
-{
- return common_route_by_name(&my_route_head, name);
-}
-
-route_head*
-route_find_track_by_name(const char* name)
-{
- return common_route_by_name(&my_track_head, name);
-}
-#endif
-
void
route_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart, int number_digits)
{
global_track_list->add_wpt(rte, wpt, false, namepart, number_digits);
}
-// FIXME: can we delete this unused and untested code?
-#ifdef DEAD_CODE_IS_REBORN
-Waypoint*
-route_find_waypt_by_name(route_head* rh, const char* name)
-{
- queue* elem, *tmp;
-
- QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) {
- Waypoint* waypointp = reinterpret_cast<Waypoint*>(elem);
- if (waypointp->shortname == name) {
- return waypointp;
- }
- }
- return nullptr;
-}
-#endif
-
void
route_del_wpt(route_head* rte, Waypoint* wpt)
{
global_track_list->sort(cmp);
}
-// FIXME: can we delete this unused and untested code?
-#ifdef DEAD_CODE_IS_REBORN
-/*
- * Move the entire track queue onto the route queue making no attempt
- * at all to "fix" anything in the process.
- */
-void
-routes_to_tracks()
-{
- queue* elem, *tmp;
-
- QUEUE_FOR_EACH(&my_route_head, elem, tmp) {
- route_head* trk = (route_head*) elem;
- dequeue(&trk->Q);
- ENQUEUE_TAIL(&my_track_head, &trk->Q);
- }
-}
-#endif
-
-// FIXME: can we delete this unused and untested code?
-#ifdef DEAD_CODE_IS_REBORN
-/*
- * Same, but in opposite direction.
- */
-void
-tracks_to_routes()
-{
- queue* elem, *tmp;
-
- QUEUE_FOR_EACH(&my_track_head, elem, tmp) {
- route_head* trk = (route_head*) elem;
- dequeue(&trk->Q);
- ENQUEUE_TAIL(&my_route_head, &trk->Q);
- }
-}
-#endif
-
-
/*
* This really makes more sense for tracks than routes.
* Run over all the trackpoints, computing heading (course), speed, and
line_width(-1),
session(curr_session())
{
- QUEUE_INIT(&Q);
QUEUE_INIT(&waypoint_list);
};
}
}
-RouteList::RouteList() : QueueList<queue>(&head, &head_ct)
-{
- QUEUE_INIT(&head);
-}
-
-int RouteList::count() const
-{
- return head_ct;
-}
-
int RouteList::waypt_count() const
{
return waypt_ct;
void
RouteList::add_head(route_head* rte)
{
- ENQUEUE_TAIL(&head, &rte->Q);
- ++head_ct;
+ this->append(rte);
}
void
RouteList::del_head(route_head* rte)
{
waypt_ct -= rte->rte_waypt_ct;
- dequeue(&rte->Q);
+ const int idx = this->indexOf(rte);
+ removeAt(idx);
delete rte;
- --head_ct;
}
void
RouteList::insert_head(route_head* rte, route_head* predecessor)
{
- ENQUEUE_AFTER(&predecessor->Q, &rte->Q);
- ++head_ct;
+ const int idx = this->indexOf(predecessor);
+ this->insert(idx + 1, rte);
}
// Synthesizing names based on the total number of waypoints in the RouteList makes
void
RouteList::common_disp_session(const session_t* se, route_hdr rh, route_trl rt, waypt_cb wc)
{
- queue* elem, *tmp;
- QUEUE_FOR_EACH(&head, elem, tmp) {
- const route_head* rhp = reinterpret_cast<route_head*>(elem);
+ foreach (const route_head* rhp, *this) {
if (rhp->session == se) {
if (rh) {
(*rh)(rhp);
void
RouteList::flush()
{
- queue* elem, *tmp;
-
- QUEUE_FOR_EACH(&head, elem, tmp) {
- queue* q = dequeue(elem);
- delete reinterpret_cast<route_head*>(q);
+ foreach (route_head* rte, *this) {
+ delete rte;
}
- head_ct = 0;
+ clear();
waypt_ct = 0;
}
void
RouteList::copy(RouteList** dst) const
{
- queue* elem, *tmp, *elem2, *tmp2;
+ queue* elem2, *tmp2;
if (*dst == nullptr) {
*dst = new RouteList;
}
const char RPT[] = "RPT";
- QUEUE_FOR_EACH(&head, elem, tmp) {
- auto rte_old = reinterpret_cast<route_head*>(elem);
-
+ foreach (const route_head* rte_old, *this) {
route_head* rte_new = route_head_alloc();
rte_new->rte_name = rte_old->rte_name;
rte_new->rte_desc = rte_old->rte_desc;
if (src == nullptr) {
return;
}
-
flush();
- QUEUE_MOVE(&head, &src->head);
- head_ct = src->head_ct;
- src->head_ct = 0;
- waypt_ct = src->waypt_ct;
+ *this = *src;
+ src->clear();
src->waypt_ct = 0;
}
void RouteList::swap(RouteList& other)
{
- queue tmp_head;
- QUEUE_MOVE(&tmp_head, &(other.head));
- QUEUE_MOVE(&(other.head), &(this->head));
- QUEUE_MOVE(&(this->head), &tmp_head);
-
- const auto tmp_head_ct = other.head_ct;
- other.head_ct = this->head_ct;
- this->head_ct = tmp_head_ct;
-
- const auto tmp_waypt_ct = other.waypt_ct;
- other.waypt_ct = this->waypt_ct;
- this->waypt_ct = tmp_waypt_ct;
+ const RouteList tmp_list = *this;
+ other = *this;
+ *this = tmp_list;
}
void RouteList::sort(Compare cmp)
{
- sortqueue(&head, cmp);
+ std::sort(begin(), end(), cmp);
}
}
}
-int SortFilter::sort_comp_rh_by_description(const queue* a, const queue* b)
+bool SortFilter::sort_comp_rh_by_description(const route_head* a, const route_head* b)
{
- const route_head* x1 = reinterpret_cast<const route_head*>(a);
- const route_head* x2 = reinterpret_cast<const route_head*>(b);
-
- return x1->rte_desc.compare(x2->rte_desc);
+ return a->rte_desc < b->rte_desc;
}
-int SortFilter::sort_comp_rh_by_name(const queue* a, const queue* b)
+bool SortFilter::sort_comp_rh_by_name(const route_head* a, const route_head* b)
{
- const route_head* x1 = reinterpret_cast<const route_head*>(a);
- const route_head* x2 = reinterpret_cast<const route_head*>(b);
-
- return x1->rte_name.compare(x2->rte_name);
+ return a->rte_name < b->rte_name;
}
-int SortFilter::sort_comp_rh_by_number(const queue* a, const queue* b)
+bool SortFilter::sort_comp_rh_by_number(const route_head* a, const route_head* b)
{
- const route_head* x1 = reinterpret_cast<const route_head*>(a);
- const route_head* x2 = reinterpret_cast<const route_head*>(b);
-
- return cmp(x1->rte_num, x2->rte_num);
+ return a->rte_num < b->rte_num;
}
int SortFilter::SortCompWptFunctor::operator()(const queue* a, const queue* b)
};
int sort_comp_wpt(const queue* a, const queue* b);
- static int sort_comp_rh_by_description(const queue* a, const queue* b);
- static int sort_comp_rh_by_name(const queue* a, const queue* b);
- static int sort_comp_rh_by_number(const queue* a, const queue* b);
+ static bool sort_comp_rh_by_description(const route_head* a, const route_head* b);
+ static bool sort_comp_rh_by_name(const route_head* a, const route_head* b);
+ static bool sort_comp_rh_by_number(const route_head* a, const route_head* b);
class SortCompWptFunctor
{